{%if $CONFIG->facebook_authorization && $CONFIG->facebook_api%}
<div id="fb-root"></div>
<script type="text/javascript">
   window.fbAsyncInit = function() {
      FB.init({
         appId      : '{%$CONFIG->facebook_api%}',
         status     : true, 
         cookie     : true,
         xfbml      : true,
         oauth      : true,
      });
      if(FB._userStatus && FB._userStatus == 'connected' && authorized == false)
      {
         authorized = 'facebook';
         switchUserLogon();
         registerSocialUser(FB._authResponse.accessToken, 'facebook');
      }
      FB.Event.subscribe('auth.statusChange', function(response){
         if(typeof response.status != 'undefined' && response.status == 'connected' && authorized == false)
         {
            authorized = 'facebook';
            switchUserLogon();
            registerSocialUser(response.authResponse.accessToken, 'facebook');
         }
      });
      FB.Event.subscribe('auth.login', function(response) {
         if(typeof response.status != 'undefined' && response.status == 'connected')
         {
            authorized = 'facebook';
            switchUserLogon();
            registerSocialUser(response.authResponse.accessToken, 'facebook');
         }
      });
      $('#authorization_methods a.fb').click(function(){
         FB.login(function(response) {
            if (response.authResponse) {
               authorized = 'facebook';
               switchUserLogon();
               registerSocialUser(response.authResponse.accessToken, 'facebook');
               /*
               console.log('Welcome!  Fetching your information.... ');
               FB.api('/me', function(response) {
                  console.log('Good to see you, ' + response.name + '.');
                  FB.logout(function(response) {
                     console.log('Logged out.');
                  });
               });
               */
            } else {
               authorized = false;
               switchUserLogon();
            }
         }, {}); // {scope: 'email'}
         return false;
      });
   };

   
   (function(d){
      var js, id = 'facebook-jssdk', s = 'script'; 
      if (d.getElementById(id)) {return;}
      js = d.createElement('script'); js.id = id; js.async = true;
      js.src = "//connect.facebook.net/ru_RU/all.js";
      d.getElementsByTagName('head')[0].appendChild(js);
   }(document));
</script>
{%/if%}
{%if $CONFIG->vkontakte_authorization && $CONFIG->vkontakte_api%}
<script src="http://vkontakte.ru/js/api/openapi.js" type="text/javascript"></script>
<script type="text/javascript">
   VK.init({apiId: {%$CONFIG->vkontakte_api%}});
   function authInfo(response) {
      if (response.session) {
         authorized = 'vkontakte';
         switchUserLogon();
         registerSocialUser(response.session.mid, 'vkontakte');
      } else {
         authorized = false;
         switchUserLogon();
      }
   }
   $(document).ready(function(){
      // VK.Auth.getLoginStatus(authInfo);
      $('#authorization_methods a.vk').click(function(){
         VK.Auth.login(authInfo);
         return false;
      });
   });
</script>
{%/if%}

<script type="text/javascript">
  window.___gcfg = {lang: 'ru'};

  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
</script>